/* === LICENSE INFO ===
 * This source file is subject to the GPLv3 license that is bundled with this
 * package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl.txt
 * === end of LICENSE INFO === */

/*==============================================================================
  File Name   : main.cpp
  Description : Test driver for GMetaInfo module.

  Created on  : 2010-06-20
  Updated on  : 2010-06-22
  Updated by  : Lee Shiou Ming

  Cautions    : (important notes)
  ============================================================================*/

//------------------------------------------------------------------------------
//-- INCLUDES & DEFINES
//------------------------------------------------------------------------------
#include "GMetaInfo/MetaInfoUtil.hpp"
#include <iostream>
#include <stdexcept>
#include <cassert>

using namespace gUtil;


//------------------------------------------------------------------------------
//-- TYPEDEF / STRUCT / UNION / ENUM
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
//-- GLOBAL
//------------------------------------------------------------------------------
const std::string g_AppName       = "Test driver";
const std::string g_AppVersion    = "1.0.1.2";
const std::string g_ModuleName    = "GMetaInfo module";
const std::string g_ModuleVersion = "1.0.2.3";


//------------------------------------------------------------------------------
//-- FUNCTION PROTOTYPES
//------------------------------------------------------------------------------
void testInitMetaVersion();
void testInitMetaInfo();
void testMetaVersionMajorChange();
void testMetaVersionMinorChange();


//------------------------------------------------------------------------------
//-- MAIN FUNCTION
//------------------------------------------------------------------------------
int main(int _argc, char* _argv[])
{
    std::cout << std::endl << "======" << std::endl;
    std::cout << g_AppName.c_str() << ", version " << g_AppVersion.c_str();
    std::cout << std::endl << "for " << g_ModuleName.c_str() <<
        ", version " << g_ModuleVersion.c_str();
    std::cout << std::endl << "======" << std::endl << std::endl;


    // Place main test code in try block.
    try
    {
        testInitMetaVersion();
        testInitMetaInfo();
        testMetaVersionMajorChange();
        testMetaVersionMinorChange();
    }
    catch (std::exception& e)
    {
        std::cerr << "[EMERGENCY] main(): " << e.what() << std::endl;
    }
    catch (...)
    {
        std::cerr << "[EMERGENCY] main(): Unknown exception detected." <<
                std::endl;
    }


    //-- Stop the console screen before quit for displaying the output.
    std::cout << std::endl << std::endl << "Press <ENTER> key to exit";
    std::cin.get();

	return 0;
}


//------------------------------------------------------------------------------
//-- FUNCTION IMPLEMENTATIONS
//------------------------------------------------------------------------------
// Test description:
// 1. Create a copy of MetaVersion and check its initial value.
// Expected behavior:
// 1. Should pass the assertion.
void testInitMetaVersion()
{
    std::string versionString;

    GMetaInfo::MetaVersion metaVersion;
    GMetaInfo::getMetaVersionString(metaVersion, versionString);
    std::cout << std::endl;
    std::cout << __FUNCTION__ << ":" << std::endl;
    std::cout << "- init metaVersion: " << versionString << std::endl;

    assert(metaVersion.m_majorVerNum == INIT_VALUE_MAJOR_VERSION);
    assert(metaVersion.m_minorVerNum == INIT_VALUE_MINOR_VERSION);
    std::cout << __FUNCTION__ << " - PASSED" << std::endl;
}


// Test description:
// 1. Create a copy of MetaInfo and check its initial value.
// Expected behavior:
// 1. Should pass the assertion.
void testInitMetaInfo()
{
    GMetaInfo::MetaInfo metaInfo;

    std::string versionString;
    GMetaInfo::getMetaVersionString(metaInfo, versionString);
    std::cout << std::endl;
    std::cout << __FUNCTION__ << ":" << std::endl;
    std::cout << "- metaId: " << metaInfo.m_id << std::endl;
    std::cout << "- metaVersion: " << versionString << std::endl;

    assert(metaInfo.m_id == INIT_VALUE_META_ID);
    assert(metaInfo.m_version.m_majorVerNum == INIT_VALUE_MAJOR_VERSION);
    assert(metaInfo.m_version.m_minorVerNum == INIT_VALUE_MINOR_VERSION);
    std::cout << __FUNCTION__ << " - PASSED" << std::endl;
}


// Test description:
// 1. Preset MetaVersion values then invoke setMetaVersionMajorChange().
// Expected behavior:
// 1. Major version number increases by 1, minor version number reset to 0.
//    Should pass the assertion.
void testMetaVersionMajorChange()
{
    GMetaInfo::MetaInfo metaInfo;

    metaInfo.m_version.m_majorVerNum = 1;
    metaInfo.m_version.m_minorVerNum = 3;
    setMetaVersionMajorChange(metaInfo);
    assert(metaInfo.m_version.m_majorVerNum == 2);
    assert(metaInfo.m_version.m_minorVerNum == 0);

    setMetaVersionMajorChange(metaInfo);
    assert(metaInfo.m_version.m_majorVerNum == 3);
    assert(metaInfo.m_version.m_minorVerNum == 0);

    std::cout << std::endl;
    std::cout << __FUNCTION__ << " - PASSED" << std::endl;
}


// Test description:
// 1. Preset MetaVersion values then invoke testMetaVersionMinorChange().
// Expected behavior:
// 1. Minor version number increases by 1, major version number unchanged.
//    Should pass the assertion.
void testMetaVersionMinorChange()
{
    GMetaInfo::MetaInfo metaInfo;

    metaInfo.m_version.m_majorVerNum = 1;
    metaInfo.m_version.m_minorVerNum = 3;
    setMetaVersionMinorChange(metaInfo);
    assert(metaInfo.m_version.m_majorVerNum == 1);
    assert(metaInfo.m_version.m_minorVerNum == 4);

    setMetaVersionMinorChange(metaInfo);
    assert(metaInfo.m_version.m_majorVerNum == 1);
    assert(metaInfo.m_version.m_minorVerNum == 5);

    std::cout << std::endl;
    std::cout << __FUNCTION__ << " - PASSED" << std::endl;
}
